/*
 * @Author: songliusheng
 * @Date: 2018-11-12 17:30:35
 * @Description: ''
 * @Last Modified by: songliusheng
 * @Last Modified time: 2018-11-12 17:32:27
 * @ToDo: ''
 */
import React from 'react'
import {Button, Popover, Input} from 'antd'
import QRCode from 'qrcode.react'

function copy (data) {
  let urlInput = document.querySelector('.url-input')
  urlInput.select()
  document.execCommand('Copy')
}
function ss () {
  let canvas = document.querySelector('.qrcode-img')
  let src = canvas && canvas.toDataURL('image/png')
  return <a className='qrcode-link' src={src}>Download QR Code</a>
}
let PromoButton = (props) => {
  let url = props.url
  let qrcodeContent = (
    <div className='qrcode pt10'>
      <Input
        type='text'
        className='url-input'
        value={url} />
      <Button
        onClick={() => copy(url)}
        className='ml10' type='primary'>Copy URL</Button>
      <QRCode
        className='qrcode-img'
        value={url} />
    </div>)
  return <Popover
    className='qrcode-pop'
    placement='bottomRight'
    content={qrcodeContent}>
    <Button
      className='ml10 promotion-btn'>Promotion</Button>
  </Popover>
}
export default PromoButton
